/**
 * 操作类
 * @constructor
 */
function ActionBtn() {
    this.value = "";
}

ActionBtn.prototype.edit = function (id) {
    this.value += "<button data-toggle='modal' href='#modal_edit_form' class='btn btn-info btn-xs' onclick='to_edit(" + id + ", this)'><i class='fa fa-edit'></i></button> ";
    return this;
};
ActionBtn.prototype.del = function (id) {
    this.value += "<button class='btn btn-danger btn-xs' onclick='del(" + id + ")'><i class='fa fa-times'></i></button> ";
    return this;
};
ActionBtn.prototype.valueOf = function () {
    return this.value;
}
ActionBtn.prototype.toString = function () {
    return this.value + '';
}

//操作栏的格式化
function actionFormatter(value, row, index) {
    var id = value;
    var result = new ActionBtn();
    result.edit(id).del(id);
    return result;
}

/**
 * 日期格式化
 * @param format
 * @returns {*}
 */
Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(),    //day
        "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时
        "H+": this.getHours(),   //小时
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1,
            (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1,
                RegExp.$1.length == 1 ? o[k] :
                    ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}

function dateFormatter(value, row, index) {
    try {
        return value == null ? "" : new Date(value).format('yyyy-MM-dd HH:mm:ss');
    } catch (e) {
        console.log("dateformatter error");
        return "";
    }
}

/**
 *  公共弹框
 */
function showMsg(type) {
    swal({
        buttons: false,
        icon: type,
        timer: 2000
    });
}